﻿using Microsoft.AspNetCore.SignalR;
using System.Reflection;

namespace CSharp.Study.SignalRTest.Hubs
{
    public class ChatHub : Hub
    {
        public override async Task OnConnectedAsync()
        {
            string id = Context.ConnectionId;
        }

        /// <summary>
        /// 1.给当前连接者发送消息 Clients.Caller.SendAsync()
        /// </summary>
        public Task SendMsg(string user, string msg)
        {
            string connId = this.Context?.ConnectionId ?? "";
            msg = DateTime.Now.ToString("yyyy-MM-dd") + msg;
            return Clients.Caller.SendAsync("ReceiveMsg", user, msg);
        }

        /// <summary>
        /// 全员发送
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public Task SendMsgToAll(string user, string msg)
        {
            return Clients.All.SendAsync("ReceiveMsg", "全员发送>>>>>>>>>>" + msg);
        }

    }
}
